feat: add event enrichment client - #4243
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4243 +/- ##
==========================================
+ Coverage 66.80% 66.95% +0.15%
==========================================
Files 1157 1170 +13
Lines 44185 44539 +354
==========================================
+ Hits 29517 29823 +306
- Misses 14668 14716 +48
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
cadivus
left a comment
There was a problem hiding this comment.
I have one nit, the rest looks good.
|
One cross platform consistency item that still stands after the recent fixes: the client id is persisted under com.amazonaws.amplify.event_enrichment.client_id, but the other platforms settled on a single shared key, com.amplifyframework.device_id, stored in plain UserDefaults. The Connect client will read the same key so that enrichment and Connect report the same stable device id for a given install. As written the two Swift packages would generate different ids. Could we switch the key here so the contract holds on Swift too? |
Issue #
None
Description
Summary
Adds
AmplifyEventEnrichmentClient— a standalone on-device event enrichment client that attaches device/app/session/identity context onto analytics events and produces a Pinpoint-compatible JSON envelope (v3.1).This is the Swift counterpart to the Flutter
amplify_event_enrichment_dartpackage (amplify-flutter#7029). It enables events sent via Kinesis/Firehose to retain the analytics context that Pinpoint previously provided automatically.Key design points
Sendableeverywhere)AmplifyFoundation; transport is delegated to theEventSinkprotocolUserDefaults(key:com.amazonaws.amplify.event_enrichment.client_id) with read-or-create pattern, matching the FlutterSharedPreferencesClientIdProviderapproachNotificationCenternotifications (same approach as the Pinpoint plugin'sActivityTracker) to pause/resume sessions on background/foreground transitionsUIDevice/WKInterfaceDevice/IOKit matching existingDeviceInfopatternsPublic API
AmplifyEventEnrichmentClientrecord(), session control, global fields, userId, closeEnrichedEventtoJson()→ Pinpoint envelopeSessionDatetimestamps + durationEventSink(protocol)EventEnrichmentClientOptionsautoSessionTracking,sessionTimeoutEventEnrichmentErrorAmplifyError-conforming error enumAppMetadata/DeviceMetadata/SDKMetadataFiles
AmplifyClients/AmplifyEventEnrichmentClient/Sources/Package.swift— new target + product addedTest plan
swift build --target AmplifyEventEnrichmentClientcompiles cleanlyswift test --filter AmplifyEventEnrichmentClientTests— 27 tests passAmplifyKinesisClientorAmplifyFirehoseClientas anEventSinkNSApplicationnotification pathGeneral Checklist
Given When Theninline code documentation and are named accordinglytestThing_condition_expectation()By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.